﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tracker.Models.BLL;
using tracker.Models;
using System.Data;
using tracker.Models.DTO;

namespace tracker.Controllers
{
   public class HandlerGetAlarmDefineInfoController : Controller
    {
       /// <summary>
       /// Get All Alarm Define
       /// </summary>
       /// <returns></returns>
        [CallAjaxFilter]
        public JsonStringResult Index()
        {
            string result = "";
            string _username = HttpContext.Session[Common.USER].ToString();
            string _language = HttpContext.Session[Common.LANGUAGE].ToString();
            _language = _language == string.Empty ? "vi" : _language;

            DataTable dt = AlarmDefineBLL.SelectAll(new string[]{EAlarmDefine.FIELD_CREATEBY},new object[]{_username}).Tables[0];
            List<EAlarmDefine> list = new List<EAlarmDefine>();

            foreach (DataRow item in dt.Rows)
            {
                EAlarmDefine ent = new EAlarmDefine();
                ent.AlarmType = ListDefineAlarm.getName(item["AlarmType"].ToString(), _language).ToString();
                ent.Expression = item["Expression"].ToString();
                ent.DefineID = item["id"].ToString();
                list.Add(ent);
            }
            dt.Dispose();
            if (list.Count > 0)
            {
                result = Utilities.getJsonString(list,"data:", 1);
            }
            else
                result = "{[]}";
            return new JsonStringResult(result);  
        }
    }
}
